package com.jdym.back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jdym.back.entity.Loan;
import com.jdym.back.entity.dto.ExcelDTO;
import com.jdym.back.entity.vo.LoanInfo;
import com.jdym.back.mapper.LoanMapper;
import com.jdym.back.service.LoanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 贷款表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-09-20
 */
@Service
public class LoanServiceImpl extends ServiceImpl<LoanMapper, Loan> implements LoanService {

    @Autowired
    LoanMapper loanMapper;

    @Override
    public List<ExcelDTO> listData(int t) {
        List<LoanInfo> dictList=null;
//        1导出审批通过的excel  2导出全部数据

        if(t==1){
            dictList = loanMapper.getAllapprovedSuc();
        }else {
            dictList = loanMapper.getAllLoanApply();
        }
//        List<LoanInfo> dictList = loanMapper.getAllapprovedSuc();
        //创建ExcelDictDTO列表，将Dict列表转换成ExcelDictDTO列表
        ArrayList<ExcelDTO> excelDTOList = new ArrayList<>(dictList.size());
        dictList.forEach(dict -> {

            ExcelDTO excelDictDTO = new ExcelDTO();
            BeanUtils.copyProperties(dict, excelDictDTO);
            excelDTOList.add(excelDictDTO);
        });
        return excelDTOList;
    }
//冲突
//    @Override
//    public List<Loan> getLoanById(int firmId) {
//        return baseMapper.selectList(new QueryWrapper<Loan>().eq("firm_id",firmId));
//    }

    @Override
    public Loan getLoanById(int firmId) {
        return baseMapper.selectById(firmId);
    }

    @Override
    public List<LoanInfo> getAllLoanApply() {
        return loanMapper.getAllLoanApply();

    }

    @Override
    public LoanInfo getAllLoanFileById(int id) {

      return  loanMapper.getAllLoanFileById(id);
    }

    @Override
    public List<LoanInfo> getAllLoanByKeyWord(String keyWord) {
        return loanMapper.getAllLoanByKeyWord(keyWord);
    }

    @Override
    public List<LoanInfo> getAllapprovedSuc() {
       return loanMapper.getAllapprovedSuc();
    }

    @Override
    public int applyLoan(Loan loan) {

        return loanMapper.applyLoan(loan);
    }

    @Override
    public List<LoanInfo> historyLoan(int firmId) {

        return loanMapper.historyLoan(firmId);
    }

    @Override
    public List<LoanInfo> getAllLoanWithMsg() {

        return loanMapper.getAllLoanWithMsg();
    }

    @Override
    public List<Loan> selectStatisics(String start, String end) {

       return loanMapper.selectStatisics(start,end);
    }


    @Override
    public void updateLoanPutId(Loan loan) {
        loanMapper.updateLoanPutId(loan);
    }

    @Override
    public Loan getLoanCobankFirm(int id) {

        return loanMapper.getLoanCobankFirm(id);
    }
}
